﻿/*
 * 利益引擎算法 数组部分 
 */
//加法函数，用来得到精确的加法结果
//说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
//调用：accAdd(arg1,arg2)
// 返回值：arg1加上arg2的精确结果
function accAdd(arg1, arg2) {
    var r1, r2, m;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2))
    return (arg1 * m + arg2 * m) / m
}
//乘法函数，用来得到精确的乘法结果
//说明：javascript的乘法结果会有误差，在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
//调用：accMul(arg1,arg2)
//返回值：arg1乘以 arg2的精确结果
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) { }
    try { m += s2.split(".")[1].length } catch (e) { }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
//保额轴：
function _eGetArray(value, start, end) {
    var beArray = new Array();
    for (var i = start; i <= end; i++) {
        beArray.push("[" + i + "," + value + "]");
    }
    return "[" + beArray + "]";
}
//保费轴：
function _eGetPeriodArray(value, start, end, period) {
    var bfArray = new Array();
    for (var i = start; i <= end; i++) {
        if (i < start + period) {
            bfArray.push("[" + i + "," + value + "]");
        } else {
            bfArray.push("[" + i + "," + 0 + "]");
        }
    }
    return "[" + bfArray + "]";
}
//累加轴1：
function _eGetCumulateItems(value, start, end, period) {
    var sumArray = new Array();
    for (var i = start; i <= end; i++) {
        if (i < start + period) {
            sumArray.push("[" + i + "," + eval(value * (i - start + 1)) + "]");
        } else {
            sumArray.push("[" + i + "," + eval(value * period) + "]");
        }
    }
    return "[" + sumArray + "]";
}
// 累加 start-istart :value   istart-iend :累加  iend-end ：最大值
function _eGetCumulateItemsB(value, start, end, iStart, iEnd) {
    var sumArray = new Array();
    var tempval = 0;
    for (var i = start; i <= end; i++) {
        if (i > iStart && i <= iEnd) {
            tempval = tempval + value;
        }
        sumArray.push("[" + i + "," + eval(tempval) + "]");
    }
    return "[" + sumArray + "]";
}

//根据value生成end-start+1长度,(S+value*0)(S+value*1)(S+value*2)...(S+value*(Period-1)(S+value*(Period))
function _eGetCumulateItemsOnS(value, start, end, period, S) {
    var sumArray = new Array();
    for (var i = start; i <= end; i++) {
        if (i < start + period) {
            sumArray.push("[" + i + "," + eval(S + value * (i - start)) + "]");
        } else {
            sumArray.push("[" + i + "," + eval(S + value * period) + "]");
        }
    }
    return "[" + sumArray + "]";
}

// 切割轴  startAge：开始年龄 endAge：结束年龄
function _eArrayCut(arr1, startAge, endAge) {
    var resultArr = new Array();
    for (var i = 0; i < arr1.length; i++) {
        var tempPoint = arr1[i];
        if (tempPoint[0] >= startAge && tempPoint[0] <= endAge) {
            continue;
        }
        resultArr.push("[" + tempPoint[0] + "," + tempPoint[1] + "]");
    }
    return "[" + resultArr + "]";
}
//累加轴2：TOTEST
function _eGetCumulateArray(arr1) {
    var resutl = new Array();
    resutl.push("[" + arr1[0][0] + "," + arr1[0][1] + "]");
    for (var i = 1; i < arr1.length; i++) {
        arr1[i][1] += arr1[i - 1][1];
        resutl.push("[" + arr1[i][0] + "," + arr1[i][1] + "]");
    }
    return "[" + resutl + "]";
}
//轴相乘：TODO
function _eArrayMulity(arr1, arr2) {
    if (Object.prototype.toString.call(arr1) != '[object Array]'
        || Object.prototype.toString.call(arr2) != '[object Array]') {
        writeLog(new Error(), "_eArrayMulity方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    if (arr1.length != arr2.length) {
        writeLog(new Error(), "_eArrayMulity方法接受的两个数组长度必须相同，当前参数长度不一致");
        return new Array();
    }
    var mutiArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        mutiArray.push("[" + arr1[i][0] + "," + eval(arr1[i][1] * arr2[i][1]) + "]");
    }
    return "[" + mutiArray + "]";
}
//轴乘常数：TODO
function _eArrayMulityValue(arr1, value) {
    if (Object.prototype.toString.call(arr1) != '[object Array]') {
        writeLog(new Error(), "_eArrayMulityValue方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    var mutiCostArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        mutiCostArray.push("[" + arr1[i][0] + "," + eval(arr1[i][1] * value) + "]");
    }
    return "[" + mutiCostArray + "]";
}
//根据value生成end-start+1长度的数组，并且处于Spec轴上的位置有值为value，其他位置为0
function _eGetSpecArray(value, start, end, Spec) {
    if (Object.prototype.toString.call(Spec) != '[object Array]') {
        writeLog(new Error(), "_eGetSpecArray方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    var existArray = new Array();
    for (var i = start; i <= end; i++) {
        if ($.inArray(i, Spec) < 0) {
            existArray.push("[" + i + "," + 0 + "]");
        } else {
            existArray.push("[" + i + "," + value + "]");
        }
    }
    return "[" + existArray + "]";
}
//两个double数组相加：TODO
function _eArrayAdd2(arr1, arr2) {
    if (Object.prototype.toString.call(arr1) != '[object Array]'
            || Object.prototype.toString.call(arr2) != '[object Array]') {
        writeLog(new Error(), "_eArrayAdd2方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    if (arr1.length != arr2.length) {
        writeLog(new Error(), "_eArrayAdd2方法接受的两个数组长度必须相同，当前参数长度不一致");
        return new Array();
    }
    var addArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        addArray.push("[" + arr1[i][0] + "," + eval(Number(arr1[i][1]) + Number(arr2[i][1])) + "]");
    }
    return "[" + addArray + "]";
}
//三个double数组相加
function _eArrayAdd3(arr1, arr2, arr3) {

    //if (Object.prototype.toString.call(arr1) != '[object Array]'
    //            || Object.prototype.toString.call(arr2) != '[object Array]'
    //            || Object.prototype.toString.call(arr3) != '[object Array]') {

    //    writeLog(new Error(), "_eArrayAdd3方法仅接受数组类型的参数，当前参数类型不对");
    //    return new Array();
    //}
    if (arr1.length != arr2.length || arr1.length != arr3.length) {
        writeLog(new Error(), "_eArrayAdd3方法接受的三个数组长度必须相同，当前参数长度不一致");
        return new Array();
    }
    var addArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        addArray.push("[" + arr1[i][0] + "," + eval(Number(arr1[i][1]) + Number(arr2[i][1]) + Number(arr3[i][1])) + "]");
    }
    return "[" + addArray + "]";
}
//不定个数轴相加：TODO
function _eArrayAdd(arr) {
    var result = new Array();
    var baseArray = arguments[0];
    for (var i = 0; i < baseArray.length; i++) {
        var tempValue = baseArray[i][1];
        for (var j = 1; j < arguments.length; j++) {
            var tempArray = arguments[j];
            tempValue = accAdd(tempValue, tempArray[i][1]);
        }
        result.push("[" + baseArray[i][0] + "," + tempValue + "]");
    }
    return "[" + result + "]";
}
//轴相减：arr1－arr2TODO
function _eArrayMinus(arr1, arr2) {
    if (Object.prototype.toString.call(arr1) != '[object Array]'
            || Object.prototype.toString.call(arr2) != '[object Array]') {
        writeLog(new Error(), "_eArrayMinus方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    var iMaxIndex = arr1.length > arr2.length ? arr1.length : arr2.length;
    var iMinIndex = arr1.length < arr2.length ? arr1.length : arr2.length;
    var minArray = new Array();
    for (var i = 0; i < iMinIndex; i++) {
        var iRest = eval(Number(arr1[i][1]) - Number(arr2[i][1]));
        if (iRest < 0) {
            iRest = 0;
        }
        minArray.push("[" + arr1[i][0] + "," + iRest + "]");
    }
    return "[" + minArray + "]";
}
//轴加常数：TODO
function _eArrayAddValue(arr1, value) {
    if (Object.prototype.toString.call(arr1) != '[object Array]') {
        writeLog(new Error(), "_eArrayAddValue方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    var addCostArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        addCostArray.push("[" + arr1[i][0] + "," + eval(Number(arr1[i]) + Number(value)) + "]");
    }
    return "[" + addCostArray + "]";
}
//分段轴：--大于等于 小于 
function _eGetSegArray(value, start, end, sIndex, bIndex) {
    var segArray = new Array();
    for (var i = start; i <= end; i++) {
        if (i >= sIndex && i < bIndex) {
            segArray.push("[" + i + "," + value + "]");
        } else {
            segArray.push("[" + i + "," + 0 + "]");
        }
    }
    return "[" + segArray + "]";
}
//分段轴：--大于等于 小于等于（从start到end的1轴上,重新赋值value从sindex到bindex.[凸起的图形包含左右两点]） 
function _eGetSegArrayB(value, start, end, sIndex, bIndex) {
    var segArray = new Array();
    for (var i = start; i <= end; i++) {
        if (i >= sIndex && i <= bIndex) {
            segArray.push("[" + i + "," + value + "]");
        } else {
            segArray.push("[" + i + "," + 0 + "]");
        }
    }
    return "[" + segArray + "]";
}
//分段轴2：点一个数组中的值  每个N年显示;一般用于每N年领回的生存金
function _eGetSegArrayPerN(arr1, n) {
    var result = new Array();
    for (var i = 0; i < arr1.length; i++) {
        if ((i + 1) % n != 0) {
            result.push("[" + arr1[i][0] + ",0]");
        } else {
            result.push("[" + arr1[i][0] + "," + arr1[i][1] + "]");
        }
    }
    return "[" + result + "]";
}

//两段轴取最小值：TODO
function _eGetSmallerArray(arr1, arr2) {
    if (Object.prototype.toString.call(arr1) != '[object Array]'
               || Object.prototype.toString.call(arr2) != '[object Array]') {
        writeLog(new Error(), "_eGetSmallerArray方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    if (arr1.length != arr2.length) {
        writeLog(new Error(), "_eGetSmallerArray方法接受的两个数组长度必须相同，当前参数长度不一致");
        return new Array();
    }
    var smallerArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        smallerArray.push("[" + arr1[i][0] + ',' + Math.min(arr1[i][1], arr2[i][1]) + "]");
    }
    return "[" + smallerArray + "]";
}
//两段轴取最大值：TODO
function _eGetBiggerArray(arr1, arr2) {
    if (Object.prototype.toString.call(arr1) != '[object Array]'
               || Object.prototype.toString.call(arr2) != '[object Array]') {
        writeLog(new Error(), "_eGetBiggerArray方法仅接受数组类型的参数，当前参数类型不对");
        return new Array();
    }
    if (arr1.length != arr2.length) {
        writeLog(new Error(), "_eGetBiggerArray方法接受的两个数组长度必须相同，当前参数长度不一致");
        return new Array();
    }
    var smallerArray = new Array();
    for (var i = 0; i < arr1.length; i++) {
        smallerArray.push("[" + arr1[i][0] + "," + Math.max(arr1[i][1], arr2[i][1]) + "]");
    }
    return "[" + smallerArray + "]";
}
// 复利计算公式
function ebte_GetACI(capital, rate, year) {
    var benefit = capital;
    for (var i = 0; i < year; i++) {
        benefit = eval(benefit + benefit * rate);
    }
    return benefit;
}
//TODO
function _eGetACI(value, start, end, period, rate) {
    var result = new Array();
    var currval = value;
    for (var i = start; i <= end; i++) {
        if (i <= period) {
            currval = currval * (1 + rate);
        }
        result.push("[" + i + "," + currval + "]");
    }
    return _eGetCumulateArray(eval("[" + result + "]"));
}
// 考虑到实际应用及算式理解，改一个算法：_eGetACICoverage(value,start,end,iStart,iEnd,rate) :
// 1)生成一个 end-start+1 的零轴（初始化为0）
// 2）自 iStart开始计算第一项计算值为 Value*1 开始，第二项 为 Value*(1+rate) ，Value*(1+rate)（1+rate）...到 iEnd结束，之后维持最后一个计算值
function _eGetACICoverage(value, start, end, iStart, iEnd, rate) {
    var result = new Array();
    var currval = value;
    for (var i = start; i <= end; i++) {
        if (i < iStart) {
            result.push("[" + i + ",0]");
            continue;
        }
        if (i == iStart) {
            result.push("[" + i + "," + value + "]");
            continue;
        }
        if (i > iStart && i <= iEnd) {
            currval = currval * (1 + rate);
        }
        result.push("[" + i + "," + currval + "]");
    }
    return "[" + result + "]";
}
//使一个数组，在start（包含）跟end（包含）之间，重新赋值为vlaue
function _eArraySegSetValue(arr1, start, end, value) {
    var result = new Array();
    for (var i = 0; i < arr1.length; i++) {
        if (arr1[i][0] >= start && arr1[i][0] <= end) {
            result.push("[" + arr1[i][0] + "," + value + "]");
        } else {
            result.push("[" + arr1[i][0] + "," + arr1[i][1] + "]");
        }
    }
    return "[" + result + "]";
}
// 使一个数组，分2段 个别乘以Value1、Value2
function _eArray2SecSetValue(array1, AgePoint1, Value1, Value2) {
    var result = new Array();
    for (var i = 0; i < array1.length; i++) {
        if (array1[i][0] <= AgePoint1) {
            result.push("[" + array1[i][0] + "," + eval(array1[i][1] * Value1) + "]");
        } else {
            result.push("[" + array1[i][0] + "," + eval(array1[i][1] * Value2) + "]");
        }
    }
    return "[" + result + "]";
}
//使一个数组，分3段 分别乘以Value1、Value2、Value3
function _eArray3SecSetValue(array1, AgePoint1, AgePoint2, Value1, Value2, Value3) {
    var result = new Array();
    for (var i = 0; i < array1.length; i++) {
        if (array1[i][0] <= AgePoint1) {
            result.push("[" + array1[i][0] + "," + eval(array1[i][1] * Value1) + "]");
        } else if (array1[i][0] > AgePoint1 && array1[i][0] <= AgePoint2) {
            result.push("[" + array1[i][0] + "," + eval(array1[i][1] * Value2) + "]");
        } else {
            result.push("[" + array1[i][0] + "," + eval(array1[i][1] * Value3) + "]");
        }
    }
    return "[" + result + "]";
}
//Offset： 偏移量开始年龄
//在原来的A数组长度基础上，自左边索引第Offset的位置上，开始加上B的第1项，接着第2项，... 直到A数组结束即停止（不论B是否结束），返回Array C；
//最终A与C会一样长度；
function _eGetdArrayApluseB(arrayA, arrayB, offset) {
    var result = new Array();
    var starindex = 0;
    for (var i = 0; i < arrayA.length; i++) {
        if (arrayA[i][0] < offset) {
            result.push("[" + arrayA[i][0] + "," + arrayA[i][1] + "]");
            // 开始索引预测是下一个索引
            starindex = i + 1;
        } else {
            var arrAValue = arrayA[i][1];
            var arrBValue = 0;

            var arrBofsIndex = i - starindex;
            if (arrBofsIndex < arrayB.length) {
                arrBValue = arrayB[arrBofsIndex][1];
            }
            var sumValue = (arrAValue - 0) + (arrBValue - 0);
            result.push("[" + arrayA[i][0] + "," + sumValue + "]");
        }
    }
    return "[" + result + "]";
}
//将 array1 + array +… 相加之和后并自我累计得到的数组
function _eArrayAddCumulate(arrays) {
    var result = new Array();
    var baseArray = arguments[0];
    for (var i = 0; i < baseArray.length; i++) {
        var tempValue = baseArray[i][1];
        for (var j = 1; j < arguments.length; j++) {
            var tempArray = arguments[j];
            tempValue += tempArray[i][1];
        }
        result.push("[" + baseArray[i][0] + "," + tempValue + "]");
    }
    return _eGetCumulateArray(eval("[" + result + "]"));
}
//将 array1 + array +… 相加之和后并自我累计得到的数组，
//再予以反转，即最后一个等于第一个，倒数第二个等于第二个
function _eArrayAddCumulateReverse(arrays) {
    var result = new Array();
    var baseArray = arguments[1];
    for (var i = 0; i < baseArray.length; i++) {
        var tempValue = baseArray[i][1];
        for (var j = 2; j < arguments.length; j++) {
            var tempArray = arguments[j];
            tempValue += tempArray[i][1];
        }
        result.push("[" + baseArray[i][0] + "," + tempValue + "]");
    }
    var sumresult = eval(_eGetCumulateArray(eval("[" + result + "]")));
    var finalRest = new Array();
    var maxValue = sumresult[sumresult.length - 1][1] - 0;
    var set0Index = arguments[0];
    for (var k = 0; k < sumresult.length; k++) {
        var revValue = maxValue - sumresult[k][1];
        if (sumresult[k][0] < set0Index) {
            revValue = 0;
        }
        finalRest.push("[" + sumresult[k][0] + "," + revValue + "]");
    }
    return "[" + finalRest + "]";
}
//获取整数部分
function _eGetA(value) {
    if (isNaN(value)) {
        return 0;
    }
    return parseInt(value);
}
//获取小数部分
function _eGeta(value) {
    if (isNaN(value)) {
        return 0;
    }
    var result = value - parseInt(value);
    return result.toFixed(2);
}
// 获取数组的最大值对应的年龄
function _eGetMaxItemAge(arrayA) {
    var max = 0;
    var maxItemAge = 0;
    for (var i = 0; i < arrayA.length; i++) {
        if (arrayA[i][1] > max) {
            max = arrayA[i][1];
            maxItemAge = arrayA[i][0]
        }
    }
    return maxItemAge;
}
// 获取数组的最大值对应的年龄
function _eGetMaxItemValue(arrayA) {
    var max = 0;
    for (var i = 0; i < arrayA.length; i++) {
        if (arrayA[i][1] > max) {
            max = arrayA[i][1];
        }
    }
    return max;
}
// 获取数组的最小值对应的年龄
function _eGetMinItemAge(arrayA) {
    var min = [0][1];
    var minItemAge = [0][0];
    for (var i = 0; i < arrayA.length; i++) {
        if (arrayA[i][1] < min) {
            min = arrayA[i][1];
            minItemAge = arrayA[i][0]
        }
    }
    return minItemAge;
}
// 获取数组的最小值
function _eGetMinItemValue(arrayA) {
    var min = arrayA[0][1];
    for (var i = 0; i < arrayA.length; i++) {
        if (arrayA[i][1] < min) {
            min = arrayA[i][1];
        }
    }
    return min;
}
// 两个Double类型的相加
function _eDoubleSumAB(a, b) {
    return a + b;
}
// 两个int类型相加
function _eIntSumAB(a, b) {
    return a + b;
}

/*
 * 参数说明：
 * Coverage：本金，即初始值
 * start、end：年龄轴长度
 * iStart、iEnd：计算开始到结束的年龄
 * rate：单利利率
 * perNYear：结算周期，就是每几年结算一次
 * initialFromA0：Boolean值，表示是否从第零项A(0) 开始
 */
function _eGetASICoverage(Coverage, start, end, iStart, iEnd, rate, perNYear, initialFromA0) {

    var result = new Array();
    var tempValue = 0;
    for (var i = start; i <= end; i++) {
        if (i < iStart) {
            result.push("[" + i + "," + 0 + "]");
            continue;
        }
        if (i == iStart) {
            tempValue = initialFromA0 == 1 ? Coverage : Coverage * (1 + rate);
            result.push("[" + i + "," + tempValue + "]");
            continue;
        }
        if (i > iStart && i <= iEnd) {
            var cYear = Math.floor((i - iStart) / perNYear);
            var count = initialFromA0 == 1 ? cYear : cYear + 1;
            tempValue = Coverage * (1 + count * rate);
            result.push("[" + i + "," + tempValue + "]");
            continue;
        }
        if (i > iEnd) {
            result.push("[" + i + "," + tempValue + "]");
        }
    }
    return "[" + result + "]";
}
/* 
  * 
  * 返回单利。Value作为本金，start是起始点，end是终点，period是缴费期间，rate是费率。 0从0开始1从1开始
  * 
  * 待定:等比基数和
  * 
  * @param value
  *            本金
  * @param start
  *            起始年龄
  * @param end
  *            结束年龄
  * @param rate
  *            利率
  * @param begin
  *            从第几项开始
  * @return Object[]
  */
function _eGetACISingle(value, start, end, rate, begin) {
    var result = new Array();
    for (var i = start; i <= end; i++) {
        var duration = i - start - begin;
        duration = duration < 0 ? 0 : duration + 1;
        var val = value * (1 + rate * duration);
        result.push("[" + i + "," + val + "]");
    }
    return "[" + result + "]";
}

/*
 * 参数说明：先把传入的数组进行相加,相加后计算每一个年龄对应的数值经过的保单年度,
 * 满几年度就*rate的几次方,0年的就为"乘以rate的0次方=1" 然后进行相加
 * array1：数组1
 * array2：数组2
 * initialFrom ：是否从第一项开始与费率相乘    1:是   0:否
 * rate：费率
 */
function _eGetArrayACI(array1) {
    if (arguments.length == 4) {
        return _eGetArrayACI2(arguments[0], arguments[1], arguments[2], arguments[3]);
    } else if (arguments.length == 5) {
        return _eGetArrayACI3(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
    }

}
function _eGetArrayACI2(array1, array2, initialFrom, rate) {
    var result = new Array();

    var midArray = eval(_eArrayAdd(array1, array2));
    if (midArray.length <= 0) {
        return midArray;
    }
    var midArray0 = midArray[0][1];
    if (initialFrom == 1) {
        midArray0 = midArray0 * (1 + rate);
    }
    midArray[0][1] = Math.round(midArray0);
    result.push("[" + midArray[0][0] + "," + midArray[0][1] + "]");
    for (var i = 1; i < midArray.length; i++) {
        var tmp = midArray[i][1];
        midArray[i][1] = midArray[i - 1][1] * (1 + rate) + tmp;
        midArray[i][1] = Math.round(midArray[i][1]);
        result.push("[" + midArray[i][0] + "," + midArray[i][1] + "]");
    }
    return "[" + result + "]";
}

function _eGetArrayACI3(array1, array2, array3, initialFrom, rate) {
    var result = new Array();

    var midArray = eval(_eArrayAdd(array1, array2, array3));
    if (midArray.length <= 0) {
        return midArray;
    }
    var midArray0 = midArray[0][1];
    if (initialFrom == 1) {
        midArray0 = midArray0 * (1 + rate);
    }
    midArray[0][1] = Math.round(midArray0);
    result.push("[" + midArray[0][0] + "," + midArray[0][1] + "]");
    for (var i = 1; i < midArray.length; i++) {
        var tmp = midArray[i][1];
        midArray[i][1] = midArray[i - 1][1] * (1 + rate) + tmp;
        midArray[i][1] = Math.round(midArray[i][1]);
        result.push("[" + midArray[i][0] + "," + midArray[i][1] + "]");
    }
    return "[" + result + "]";
}
/*
 * 把一个图形(数组),在X轴上向左或向右平移,平移N个单位,平移后最终保留的数轴的起点及终点
 * double[] array1	传入一个数组
 * moveway	移动方向  0 为向左移动; 1 为向右移动
 * movesetN	移动几个"年龄"即 X轴上移动几个位置
 * double start 	移动后数轴的起点
 * double  end	移动后数轴的终点
 */
function _eGetMoveItem(array1, moveway, movesetN, start, end) {
    var result = new Array();

    var startAge;
    if (moveway == 0) {
        startAge = array1[0][0] - movesetN;
    } else {
        startAge = array1[0][0] + movesetN;
    }

    for (var j = start; j < startAge; j++) {
        result.push("[" + j + ",0]");
    }

    for (var i = 0; i < array1.length; i++) {
        var movedAge;
        if (moveway == 0) {
            movedAge = array1[i][0] - movesetN;
        } else {
            movedAge = array1[i][0] + movesetN;
        }

        if (movedAge < start) {
            continue;
        } else if (movedAge > end) {
            break;
        }
        result.push("[" + movedAge + "," + array1[i][1] + "]");
    }

    var endAge;
    if (moveway == 0) {
        endAge = array1[array1.length - 1][0] - movesetN;
    } else {
        endAge = array1[array1.length - 1][0] + movesetN;
    }
    for (var j = endAge + 1; j <= end; j++) {
        result.push("[" + j + ",0]");
    }
    return "[" + result + "]";
}

/*
 * 由于是从投保年龄起开始按照一年给付,1年不给付来做;所以,当出现例2中的情况,即投保年龄到领取年金的年龄不能整除n
 * 时,会往后移1年,不是我们要的,我们要的就是30岁有,31岁无,32岁有……
 * @param para1
 *            -原数组
 * @param n
 *            每隔n年
 * @param ageSet
 *            -起始值,从ageSet起，每隔n年有值
 * @return
 */
function _eGetSegSetArrayPerN(para1, n, ageSet) {

    var result = new Array();
    for (var i = 0; i < para1.length; i++) {
        if (para1[i][0] >= ageSet && (para1[i][0] - ageSet) % n == 0) {
            result.push("[" + para1[i][0] + "," + para1[i][1] + "]");
        } else {
            result.push("[" + para1[i][0] + ",0]");
        }
    }
    return "[" + result + "]";
}
/*
 *  引擎内容包括5项,第1-3项为判断试,如果判断式为真,则取第4项值,如果判断式为假,则取第5项值
    判断条件可以为Value或年龄等
 *
 *
 *
 */
function _eIf(parm1, parm2, parm3, parm4, parm5) {
    if (parm1 >= parm2 && parm1 <= parm3) {
        return parm4;
    } else {
        return parm5;
    }
}



/**
 * 
 * 累积复利计算-每年都注入资金
 * 
 * @param rate
 * @param array
 * @param start
 *            --从第start年开始计算复利start>=1
 * @return
 * @return Object[]
 * @throw
 */
function compoundPlus(rate, array, start) {
    if (array == null || array.length <= 0) {
        return array;
    }
    var dd;
    var ddPre;
    for (var i = 0; i < array.length; i++) {
        dd = array[i];
        if (i - 1 >= 0) {
            ddPre = array[i - 1];
            var num = dd[1]-0 + ddPre[1]-0;
            dd[1] = num.toFixed(2) - 0;
        }
        if ((i + 1 - start) >= 0) {
            var  num=accMul(dd[1], (1 + rate));
            
            dd[1] = num.toFixed(2)-0;
        }
    }
    return array;
}
/**
	 * 万能账户:
	 * <p>
	 * 1. 把领回的生存金,存入万能账户,在万能账户中做累计生息,这些生存金在标准利益中,一定已经为某个利益项,用array表现了,
	 * 该公式只需要吧array套用进来即可;
	 * <p>
	 * 2.rate为计算的利率 3.initialFromAge是,从哪年开始进行Rate的计算
	 * 
	 * @param rate
	 * @param array1
	 * @param initialFromAge1
	 * @param array2
	 * @param initialFromAge2
	 * @return
	 * @return Object[]
	 * @throw
	 */
function _eGetUnvslAccnt(rate, array1, initialFromAge1, array2, initialFromAge2) {
    var result = null;
    for (var i = 1; i < arguments.length - 1; i = i + 2) {
        var o1 = compoundPlus(rate, arguments[i], arguments[i + 1]);
        if (result == null) {
            result = o1;
        } else {
            result = eval(_eArrayAdd(result, o1));
        }
    }
    var arr = new Array();
    for (var i = 0; i < result.length; i++) {
        arr.push("[" + result[i][0] + "," + result[i][1] + "]");
    }
    return "[" + arr + "]";
}



